/*
 * NextAction.java
 *
 * Created on June 22, 2005, 8:33 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.bjj.utils.Resources;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.exception.SlimException;

/**
 *
 * @author Bill
 */
public class PlaylistLoopAction extends AbstractAction {

    SlimPlaylist playlist = null;

    /** Creates a new instance of StopAction */
    public PlaylistLoopAction(SlimPlaylist playlist) {
        super(Resources.getMessage(Resources.LABEL_KEY.ACTION_PLAYLIST_LOOP_NAME));
        this.playlist = playlist;

        try {
            checkLoopingStatus();
        } catch (SlimException ex) {
            Logger.getLogger(PlaylistLoopAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        try {
            setStatus();
        } catch (SlimException ex) {
            Logger.getLogger(PlaylistLoopAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void checkLoopingStatus() throws SlimException {
        if (playlist.isRepeatingPlaylist()) {
            putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_PLAYLIST_UNLOOP_NAME));
            putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_PLAYLIST_UNLOOP_SHORT_DESC));
            //putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_PLAYLIST_UNLOOP));
        } else {
            putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_PLAYLIST_LOOP_NAME));
            putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_PLAYLIST_LOOP_SHORT_DESC));
            //putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_PLAYLIST_LOOP));
        }
    }

    public void checkStatus() throws SlimException {
        checkLoopingStatus();
    }

    public void setStatus() throws SlimException {
        if (playlist.isRepeatingPlaylist()) {
            playlist.repeatOff();
        } else {
            playlist.repeatPlaylist();
        }
        checkStatus();
    }
}
